package com.wang.web3.weight;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.wang.web3.R;
import com.wang.web3.bean.PropsBean;

/**
 * Created by SAR on 2018/4/9.
 */

public class PropsWindow extends DialogFragment implements View.OnClickListener{


    ImageView iv_props;
    TextView tv_props_info1;

    PropsWindowOnClick propsWindowOnClick;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.props_dialog, container, false);
        iv_props = v.findViewById(R.id.iv_props);
        tv_props_info1 = v.findViewById(R.id.tv_props_info1);
        v.findViewById(R.id.mBtnCreateSale).setOnClickListener(this);
        v.findViewById(R.id.mBtnCreateBuy).setOnClickListener(this);
        Bundle bundle  = getArguments();
//        PropsBean propsBean = (PropsBean) bundle.getSerializable("PropsBean");
//        if (propsBean.getType() == 0){
//            iv_props.setImageDrawable(getResources().getDrawable(R.drawable.wings));
//        }else{
//            iv_props.setImageDrawable(getResources().getDrawable(R.drawable.photoframe1));
//        }
//        tv_props_info1.setText(propsBean.getInfo());

        return v;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    public void upDate(String info){
        tv_props_info1.setText(info);
    }

    public void onStart()
    {
        super.onStart();
        DisplayMetrics dm = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics( dm );
        getDialog().getWindow().setLayout( dm.widthPixels, getDialog().getWindow().getAttributes().height );
    }

    public void initOnClick(PropsWindowOnClick propsWindowOnClick){
        this.propsWindowOnClick = propsWindowOnClick;
    }

    public static PropsWindow show(FragmentManager fragmentManager, PropsBean propsBean) {
        PropsWindow propsWindow = new PropsWindow();
        Bundle bundle = new Bundle();
        bundle.putSerializable("PropsBean", propsBean);
        propsWindow.setArguments(bundle);
        propsWindow.show(fragmentManager, "propsWindow");
        return  propsWindow;
    }

    @Override
    public void onClick(View v) {
        propsWindowOnClick.onClick(v);
    }

    public interface PropsWindowOnClick{
        void onClick(View v);
    }
}
